package com.itheima.array;

/*
   定义数组并打印每一个数组出现的次数
 */
public class WorkArray02 {
    public static void main(String[] args) {
        //1.定义数组
        int[] arr = {1, 2, 2, 2, 3, 3, 4, 4, 4, 4};
        print(arr);
    }

    public static void print(int[] arr) {
        int[][] save = new int[10][10];
        save[0][0] = arr[0];
        int i;
        int[] j = new int[10];
        int a = 1;
        int b = 1;
        for (i = 1; i < arr.length; i++) {
            a++;
            for (int m = 0; m < i; m++) {
                if (arr[i] == save[m][0]) {
                    j[m]++;
                    save[m][j[m]] = arr[i];
                    b++;
                } else if (arr[i] != save[m][0] && m == (a - b - 1)) {
                    save[a - b][0] = arr[i];
                }

            }
        }
        for (int n = 0; n < save.length; n++) {
            System.out.println("数字" + save[n][0] + "出现了" + j[n] + "次");
        }
    }
}
